package com.tian.controller;

import com.tian.mapper.PatientsMapper;
import com.tian.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.tian.pojo.Patients;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping(value = "/")
public class PatientController {

//    @Autowired
//    Private


    @CrossOrigin
    @RequestMapping(value = "/inputmsg", method = RequestMethod.POST)
    @ResponseBody
    public String deleteBook(@RequestBody Map<String,Object> map) throws Exception{

        Patients patients = new Patients();
        patients.setId(Integer.parseInt(String.valueOf(map.get("id"))));
        patients.setName(String.valueOf(map.get("name")));
        patients.setSex(String.valueOf(map.get("sex")));
        patients.setAge(Integer.parseInt(String.valueOf(map.get("age"))));

        System.out.println("插入病人信息数据");
        patientsMapper.insert(patients);


        //给前端返回的必须是String类型
//        ObjectMapper objectMapper = new ObjectMapper();

        return "SUCCESS";
    }


    @Autowired
    private PatientsMapper patientsMapper;

    @RequestMapping("/PatientName")
    public List<Patients> findAll(){
        return patientsMapper.findAll();
    }

    @RequestMapping("/")
    public List<User> findUser(){
        return patientsMapper.findUser();
    }

}
